package com.ftg.learn.course.controller;

import com.ftg.learn.course.dto.CategoryDto;
import com.ftg.learn.course.entity.Category;
import com.ftg.learn.course.result.Result;
import com.ftg.learn.course.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/category")
@Tag(name = "课程分类管理模块")
@AllArgsConstructor
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @Operation(summary = "获取所有课程分类")
    @GetMapping("/getAll")
    public Result<List<Category>> getAll() {
        return categoryService.getAll();
    }
    @Operation(summary = "获取分类详情")
    @GetMapping
    public Result<Category> getOne(@RequestParam Long id) {
        return categoryService.MyGetOne(id);
    }
    @Operation(summary = "添加分类")
    @PostMapping
    public Result<String> add(@RequestBody CategoryDto categoryDto) {
        return categoryService.add(categoryDto);
    }
    @Operation(summary = "修改分类")
    @PutMapping
    public Result<String> update(@RequestBody Category category) {
        return categoryService.MyUpdate(category);
    }
    @Operation(summary = "删除分类")
    @DeleteMapping
    public Result<String> delete(@RequestParam Long id) {
        return categoryService.MyDelete(id);
    }

}
